package ns2;

import java.text.DecimalFormat;

public class NSMobilityItem {
	private int 	id;
    private int     timestep;
    private double  x;
    private double  y;
    private double  speed;
    
    public NSMobilityItem(int timestep, int id, double x, double y, double speed) 
    {
        this.timestep = timestep;
        this.id = id;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }

    public int getTimestep() {
        return timestep;
    }

    public int getId() {
        return id;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public String getFormattedX() {
        DecimalFormat df = new DecimalFormat("#.##");
        return df.format(x);
    }

    public String getFormattedY() {
        DecimalFormat df = new DecimalFormat("#.##");
        return df.format(y);
    }
    
    public double getSpeed() {
        return speed;
    }
    public String getFormattedSpeed() {
        DecimalFormat df = new DecimalFormat("#.##");
        return df.format(speed);
    }

    public void setTimestep(int timestep) {
        this.timestep = timestep;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setX(double x) {
        this.x = x;
    }

    public void setY(double y) {
        this.y = y;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    @Override
    public String toString() {
        StringBuffer output = new StringBuffer();
        if( this.getTimestep() == -1){         
            output.append("$node_(" + this.getId() + ") set " + "X_ " + this.getFormattedX() + "\r\n"); //X register
            output.append("$node_(" + this.getId() + ") set " + "Y_ " + this.getFormattedY()); //Y register
        }
        else{
            output.append("$ns_ at ");
            output.append(this.getTimestep());        //The corresponding timestep
            output.append(" \"$node_(");
            output.append(this.getId() );             //The vehicle which performs the movement
            output.append(") setdest ");
            output.append(this.getX() + " ");         //The x coordinate of the node's position in the lane
            output.append(this.getY() + " ");         //The y coordinate of the node's position in the lane
            output.append(this.getSpeed() + "\"");    //The node's speed
        }
        
        return output.toString();
    }
    
    
}
